<?php

    $name = $_POST['userName'];
    $pass = $_POST['password'];
    require('db_connection.php');

    $query1 = "SELECT password('$pass')";
    $result1 = mysql_query($query1);
    while ($row = mysql_fetch_array($result1))
    {
      $passw = $row["password('$pass')"];

    }

    $query = "SELECT * FROM tbladmin WHERE userName like '$name' AND password like '$passw'";
    $result = mysql_query($query);

  while ($row = mysql_fetch_array($result))
    {
      $userType = $row['userType'];
      $firstName = $row['firstName'];
      $libraryNo = $row['libraryNo'];
      //echo $row['userType'];
    }


if($userType == 'administrator')
{
    setcookie("firstName",$firstName);
    setcookie("userType",$userType);
    setcookie("libraryNo",$libraryNo);
    setcookie("password",$passw);
    setcookie("userName",$name);
    
    echo"'<script>document.location.href='main.php'</script>'";;
}

if($userType == 'superadministrator')
{
    setcookie("firstName",$firstName);
    setcookie("userType",$userType);
    setcookie("libraryNo",$libraryNo);
    setcookie("password",$passw);
    setcookie("userName",$name);

    echo"'<script>document.location.href='mainsad.php'</script>'";

}

if($userType == 'staff')
{
    setcookie("userName",$name);
    setcookie("userType",$userType);
    setcookie("password",$pass);
    setcookie("password",$passw);
    setcookie("userName",$name);

    echo"'<script>document.location.href='main.php'</script>'";
}


if($userType == '')
{
    echo"'<script>document.location.href='index.php'</script>'";
}


?>


